// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) KALEIDOS INC

@use "ds/typography.scss" as t;
@use "ds/_sizes.scss" as *;
@use "ds/_borders.scss" as *;
@use "ds/mixins.scss" as *;
@use "ds/_utils.scss" as *;

.color-data {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  position: relative;

  &:hover {
    --reorder-icon-visibility: visible;
  }

  &.dnd-over-top {
    --reorder-top-display: block;
  }

  &.dnd-over-bot {
    --reorder-bottom-display: block;
  }
}

.hidden {
  display: none;
}

.color-info {
  --detach-icon-foreground-color: none;

  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  flex: 1;
  gap: var(--sp-xxs);
  block-size: $sz-32;
  border-radius: $br-8;
  background-color: var(--color-background-primary);

  &:hover {
    --detach-icon-foreground-color: var(--color-foreground-primary);
  }
}

.color-name-wrapper {
  --color-name-wrapper-background-color: var(--color-background-tertiary);
  --color-name-wrapper-foreground-color: var(--color-foreground-primary);
  --color-name-wrapper-boder-color: var(--color-background-tertiary);
  @include t.use-typography("body-small");
  @include textEllipsis;
  display: flex;
  align-items: center;
  flex-grow: 1;
  gap: var(--sp-xs);
  block-size: $sz-32;
  min-inline-size: 0;
  inline-size: 100%;
  padding: 0;
  margin-inline-end: 0;
  border: $b-1 solid var(--color-name-wrapper-boder-color);
  border-radius: $br-8;
  background-color: var(--color-name-wrapper-background-color);
  color: var(--color-name-wrapper-foreground-color);
  border-radius: $br-8 0 0 $br-8;

  &.no-opacity {
    border-radius: $br-8;
    .color-input-wrapper {
      border-radius: $br-8;
    }
  }

  &:hover {
    --detach-icon-foreground-color: var(--input-foreground-color-active);
    --color-name-wrapper-background-color: var(--color-background-quaternary);
    --color-name-wrapper-boder-color: var(--color-background-quaternary);

    .detach-btn {
      display: grid;
    }
    &.editing {
      --color-name-wrapper-background-color: var(--color-background-primary);
    }

    &:focus,
    &:focus-within {
      --color-name-wrapper-background-color: var(--color-background-tertiary);
      --color-name-wrapper-boder-color: var(--color-accent-primary);
    }
  }

  &:focus,
  &:focus-within {
    --color-name-wrapper-background-color: var(--color-background-tertiary);
    --color-name-wrapper-boder-color: var(--color-accent-primary);
    &:hover {
      --color-name-wrapper-background-color: var(--color-background-quaternary);
    }
  }

  &.editing {
    --color-name-wrapper-background-color: var(--color-background-primary);
    &:hover {
      --color-name-wrapper-boder-color: var(--color-accent-primary);
    }
  }
}

.detach-btn {
  display: none;
  background: var(--color-name-wrapper-background-color);
}

.color-input-wrapper {
  @include t.use-typography("body-small");
  display: flex;
  align-items: center;
  flex-grow: 1;
  block-size: $sz-28;
  inline-size: 100%;
  padding: 0;
  margin: 0;
  background-color: var(--color-name-wrapper-background-color);
  color: var(--color-name-wrapper-foreground-color);
  border-radius: 0;
}

.color-name {
  @include t.use-typography("body-small");
  @include textEllipsis;
  flex-grow: 1;
  padding-inline: px2rem(6);
  border-radius: $br-8;
  color: var(--color-name-wrapper-foreground-color);
}

.color-bullet-wrapper {
  display: flex;
  align-items: center;
  position: relative;
  block-size: $sz-32;
  padding: 0 var(--sp-xxs) 0 var(--sp-s);
  border-radius: $br-8 0 0 $br-8;
  background-color: transparent;
  &:hover {
    background-color: transparent;
  }
}

.color-input {
  @include textEllipsis;
  border: none;
  background: none;
  outline: none;
  block-size: $sz-28;
  inline-size: 100%;
  flex-grow: 1;
  margin: var(--sp-xxs) 0;
  padding: 0 0 0 px2rem(6);
  border-radius: $br-8;
  color: var(--input-foreground-color-active);
  &[disabled] {
    opacity: 0.5;
    pointer-events: none;
  }
}

.library-name-wrapper {
  border-radius: $br-8;
}

.opacity-element-wrapper {
  --opacity-input-background-color: var(--color-background-tertiary);
  --opacity-input-boder-color: var(--color-background-tertiary);

  @include t.use-typography("body-small");
  display: flex;
  align-items: center;
  block-size: $sz-32;
  inline-size: px2rem(60);
  padding-inline-start: var(--sp-xs);
  border-radius: 0 $br-8 $br-8 0;
  border: $b-1 solid var(--opacity-input-boder-color);
  background-color: var(--opacity-input-background-color);

  &:hover {
    --opacity-input-background-color: var(--color-background-quaternary);
    --opacity-input-boder-color: var(--color-background-quaternary);

    .detach-btn {
      display: grid;
    }
    &.editing {
      --opacity-input-background-color: var(--color-background-primary);
    }

    &:focus,
    &:focus-within {
      --opacity-input-background-color: var(--color-background-tertiary);
      --opacity-input-boder-color: var(--color-accent-primary);
    }
  }

  &:focus,
  &:focus-within {
    --opacity-input-background-color: var(--color-background-tertiary);
    --opacity-input-boder-color: var(--color-accent-primary);
    &:hover {
      --opacity-input-background-color: var(--color-background-quaternary);
    }
  }

  &.editing {
    --opacity-input-background-color: var(--color-background-primary);
    &:hover {
      --opacity-input-boder-color: var(--color-accent-primary);
    }
  }
}

.opacity-input {
  @include textEllipsis;
  block-size: $sz-28;
  min-inline-size: $sz-28;
  flex-grow: 1;
  inline-size: 100%;
  padding: 0;
  border-radius: 0 $br-8 $br-8 0;
  border: none;
  background: none;
  outline: none;
  margin: var(--sp-xxs) 0;
  padding: 0 0 0 px2rem(6);
  color: var(--color-foreground-primary);
  &[disabled] {
    opacity: 0.5;
    pointer-events: none;
  }
}

.icon-text {
  display: flex;
  justify-content: center;
  align-items: center;
  block-size: $sz-32;
  margin-inline-end: var(--sp-xs);
  margin-block-start: var(--sp-xxs);
  color: var(--color-foreground-secondary);
}

// TOKEN ROW

.token-color-wrapper {
  --token-color-wrapper-background-color: var(--color-background-tertiary);
  --token-color-wrapper-foreground-color: var(--color-token-foreground);
  --token-color-wrapper-border-color: var(--color-token-border);
  --token-actions-display: none;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--sp-xs);
  block-size: $sz-32;
  min-inline-size: 0;
  inline-size: 100%;
  padding: 0;
  margin-inline-end: 0;
  background: var(--token-color-wrapper-background-color);
  border: $b-1 solid var(--token-color-wrapper-border-color);
  border-radius: $br-8;
  &:hover {
    --token-color-wrapper-background-color: var(--color-token-background);
    --token-color-wrapper-foreground-color: var(--color-foreground-primary);
    --token-color-wrapper-border-color: var(--color-token-accent);
    --token-actions-display: flex;
  }
}

.token-color-with-errors,
.token-color-not-active {
  --token-color-wrapper-background-color: var(--color-background-primary);
  --token-color-wrapper-foreground-color: var(--color-foreground-secondary);
  --token-color-wrapper-border-color: var(--color-token-border);
  &:hover {
    --token-color-wrapper-background-color: var(--color-background-primary);
    --token-color-wrapper-foreground-color: var(--color-foreground-secondary);
    --token-color-wrapper-border-color: var(--color-token-background);
    --token-actions-display: flex;
  }
}

.token-name {
  @include t.use-typography("body-small");
  @include textEllipsis;
  color: var(--token-color-wrapper-foreground-color);
  block-size: $sz-32;
  line-height: $sz-32;
}

.token-tooltip {
  min-width: 0;
  inline-size: inherit;
}

.token-name-tooltip {
  color: var(--color-foreground-primary);
}

.token-actions {
  display: var(--token-actions-display);
  justify-self: flex-end;
  align-items: center;
}

.error-dot {
  inline-size: px2rem(4);
  block-size: px2rem(4);
  border-radius: 50%;
  background-color: var(--color-foreground-error);
  margin-inline-start: var(--sp-xs);
  position: absolute;
  inset-inline-end: px2rem(1);
  inset-block-start: px2rem(5);
}
